<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>class类get和set</title>
</head>

<body>
  <script>
    // get 和 set
    class Phone {
      constructor(number) {
        this.number = number
      }

      get price() {
        console.log("价格被读取了")
        return this.number
      }

      set price(newVal) {                 // set函数必须设置参数 有且只有一个 否则报错   Uncaught SyntaxError: Setter must have exactly one formal parameter.
        console.log("价格被修改了");
        this.number = newVal
      }
    }

    let s = new Phone(2499);      // get函数被调用  价格被读取了

    console.log(s.price);     // 2499
    s.price = 3699
    console.log(s.price);     // 3699
  </script>
</body>

</html>